package com.loozb.thread2;

/**
 * 线程优先级设置
 * @author 龙召碧
 * @create 2018-01-30 16:07
 **/
public class PriorityDemo {
    public static class HightPriority extends Thread {
        static int count = 0;
        public void run() {
            while (true) {
                synchronized (PriorityDemo.class) {
                    count ++;
                    if(count > 10000000) {
                        System.out.println("HightPriority is complete");
                        break;
                    }
                }
            }
        }
    }

    public static class LowPriority extends Thread {
        static int count = 0;
        public void run() {
            while (true) {
                synchronized (PriorityDemo.class) {
                    count ++;
                    if(count > 10000000) {
                        System.out.println("LowPriority is complete");
                        break;
                    }
                }
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread h = new HightPriority();
        Thread l = new LowPriority();
        h.setPriority(Thread.MAX_PRIORITY);
        l.setPriority(Thread.MIN_PRIORITY);
        l.start();
        h.start();
    }
}
